package com.tjetc.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionManager;

import java.io.IOException;

public class Db {
    private static SqlSessionManager sqlSessionManager;

    static {
        try {
            sqlSessionManager = SqlSessionManager.newInstance(Resources.getResourceAsStream(
                    "mybatis.xml"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static <T> T getMapper(Class<T> clazz) {
        return sqlSessionManager.getMapper(clazz);
    }
    public static void start() {
        sqlSessionManager.startManagedSession();
    }
    public static void commit() {
        sqlSessionManager.commit();
    }
    public static void rollback() {
        sqlSessionManager.rollback();
    }
    public static void close() {
        sqlSessionManager.close();
    }

}
